package com.sample.springbatch.job.sample.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ExitStatus;
import org.springframework.stereotype.Service;

/**
 * Created by zwg on 2017/8/8.
 */
@Service
public class TaskletStepService {

    private static final Logger logger = LoggerFactory.getLogger(TaskletStepService.class);

    public ExitStatus showMe(){
        for(int i=0; i < 1000; i++) {
            logger.info("===========外部实现类showMe被执行["+i+"]=============");
        }
        return new ExitStatus("检查未通过");
    }

    public ExitStatus showMe2(){
        for(int i=0; i < 100; i++) {
            logger.info("===========外部实现类showMe2被执行["+i+"]=============");
        }
        return new ExitStatus("检查通过");
    }

    public ExitStatus execOk(){
        ExitStatus es = ExitStatus.COMPLETED;
        logger.info("测试执行完成");
        return es;
    }


    public ExitStatus execError(){
        ExitStatus es = ExitStatus.COMPLETED;
        for(int i=0; i < 100; i++) {
            logger.info("===========外部实现类execError被执行["+i+"]=============");
            try {
                Thread.sleep(100L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        logger.info("测试执行错误,空指针异常");
        String[] arr = new String[1];
        arr[3]="1";
        return es;
    }
}
